Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Problem with na.spline function in R

$
0
0

@nikos_agroapps wrote:

I have an excel file containing 6 rows and 5 columns. Some cells has NA values and I want to interpolate them using the na.spline function in R. But I am getting the following error:
Error in splinefun(x[!na], y[!na], …) : zero non-NA points
In addition: Warning message:
In xy.coords(x, y, setLab = FALSE) : NAs introduced by coercion

Here is the code I have used so for and here is a link to the excel file.
df = read_excel(“2017_NDVI_Anomaly_Zonal_Stats.xlsx”, sheet = “Sheet4”)
colnames(df)
class(df)

#convert the column Date from character to date format
df$DATE <- as.Date(df$DATE, format = "%y-%m-%d")
str(df$DATE)

#remove the 1st column of the excel
df <- subset(df, select = -c(RowID))

#convert the character columns to numeric
df %<>% mutate_if(is.character,as.numeric)
class(df$DATE)
str(df$`155_4sel`)

#check the format of the columns
df[] <- lapply(df, function(x) {
  if(is.factor(x)) as.numeric(as.character(x)) else x
})
sapply(df, class)

#convert all character cells to null
df[is.character(df)]= NULL
View(df)

df[which(is.character(df))] <- NULL

sum(is.na(df))

df1 = na.spline(df)

Any thoughts?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles